namespace OFX.Aggregator.Implementation.Serializer
{
	using System.IO;
	using System.Xml.Serialization;

	using Infrastructure;

	public class XmlMemoryStreamStatementSerializer : IStatementSerializer
	{
		#region IStatementSerializer Members

		public Stream Serialize(Statement statement)
		{
			var writeStream = new MemoryStream();

			try
			{
				var serializer = new XmlSerializer(typeof(Statement));

				serializer.Serialize(writeStream, statement);

				Stream stream = writeStream;
				writeStream = null;

				return stream;
			}
			finally
			{
				if (writeStream != null)
					writeStream.Dispose();
			}
		}

		#endregion
	}
}